package com.huabo.contract.oracle.mapper;

import com.hbfk.util.PageInfo;
import com.huabo.contract.oracle.entity.TblContractAppendixsigning;

import java.math.BigDecimal;
import java.util.List;

import org.apache.ibatis.annotations.*;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author huabo
 * @since 2021-10-29
 */
public interface TblContractAppendixsigningMapper extends BaseMapper<TblContractAppendixsigning> {

	@Select("SELECT TAC.SINGINGID,TAC.SINGINGNAME,TAC.SINGINGPATH,TAC.SINGINGSIZE,TAC.PDFVIEWFILEPATH,TAC.SINGINGTYPE,TAC.SINGINGSTATUS,TAC.CONSTRACTID,TAC.UPLOADTIME,TAC.UPLOADER,TS.REALNAME FROM TBL_CONTRACT_APPENDIXSIGNING TAC LEFT JOIN TBL_STAFF TS ON TAC.UPLOADER = TS.STAFFID WHERE CONSTRACTID = #{contractid}")
	@Results({
		@Result(column="SINGINGID",property="singingId"),
		@Result(column="SINGINGNAME",property="singingName"),
		@Result(column="PDFVIEWFILEPATH",property="pdfViewFilePath"),
		@Result(column="SINGINGPATH",property="singingPath"),
		@Result(column="SINGINGSIZE",property="singingSize"),
		@Result(column="SINGINGTYPE",property="singingType"),
		@Result(column="SINGINGSTATUS",property="singingStatus"),
		@Result(column="CONSTRACTID",property="constractId"),
		@Result(column="UPLOADTIME",property="uploadTime"),
		@Result(column="UPLOADER",property="uploader"),
		@Result(column="REALNAME",property="uploaderName"),
	})
	List<TblContractAppendixsigning> findFileListByContractId(@Param("contractid") BigDecimal contractid) throws Exception;

	@Select("SELECT COUNT(0) FROM TBL_CONTRACT_APPENDIXSIGNING WHERE CONSTRACTID = #{contractId}")
	Integer findFileCountByContractId(String contractId);

	@SelectProvider(type=TblContractAppendixsigningMapperSqlConifg.class,method="findFileListByContractIdPageInfo")
    List<TblContractAppendixsigning> findFileListByContractIdPageInfo(PageInfo<TblContractAppendixsigning> pageInfo);

	@SelectProvider(type=TblContractAppendixsigningMapperSqlConifg.class,method="findCountFileListByContractIdPageInfo")
	Integer findCountFileListByContractIdPageInfo(PageInfo<TblContractAppendixsigning> pageInfo);

	@Select("SELECT * FROM TBL_CONTRACT_APPENDIXSIGNING WHERE SINGINGID = #{singingId}")
    TblContractAppendixsigning findBysingingId(Integer singingId);

	@Delete("DELETE FROM TBL_CONTRACT_APPENDIXSIGNING WHERE SINGINGID = #{singingId}")
	void deleteBySingingId(Integer singingId);
	
	@Insert("INSERT INTO TBL_CONTRACT_APPENDIXSIGNING(SINGINGID,SINGINGNAME,SINGINGPATH,SINGINGSIZE,SINGINGTYPE,SINGINGSTATUS,CONSTRACTID,UPLOADTIME,UPLOADER) VALUES(HIBERNATE_SEQUENCE.nextval,#{singingName},#{singingPath},#{singingSize},#{singingType},#{singingStatus},#{constractId},#{uploadTime},#{uploader})")
	@Options(useGeneratedKeys=true, keyProperty="singingId", keyColumn="SINGINGID")
	void saveEntity(TblContractAppendixsigning signing);

	@Select("SELECT COUNT(*) FROM TBL_CONTRACT_APPENDIXSIGNING WHERE CONSTRACTID = #{contractid} AND SINGINGTYPE = #{type}")
	Integer selectCountByContractId(BigDecimal contractid, int type) throws Exception;
}
